<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 大盒子 */
        .cont {
            width: 500px;
            height: 400px;
            margin: 20px auto;
            position: relative;
        }

        /* 轮播图四张图片 */
        .cont>div {
            width: 100%;
            height: 400px;
            position: absolute;
        }

        .cont>.cont_list:nth-child(1) {
            background-color: rgb(135, 135, 248);
        }

        .cont>div:nth-child(2) {
            background-color: rgb(214, 62, 245);
        }

        .cont>div:nth-child(3) {
            background-color: rgb(101, 177, 39);
        }

        .cont>div:nth-child(4) {
            background-color: rgb(218, 124, 1);
        }

        /* 按钮 */
        .btn {
            width: 500px;
            margin: 0 auto;
            display: flex;
            justify-content: space-around;
            user-select: none;
        }

        .btn>div {
            width: 40px;
            background-color: #ccc;
            text-align: center;

        }
    </style>
</head>

<body>
    <div class="cont">
        <div class="cont_list">1</div>
        <div class="cont_list">2</div>
        <div class="cont_list">3</div>
        <div class="cont_list">4</div>
    </div>
    <div class="btn">
        <div class="btn_list">1</div>
        <div class="btn_list">2</div>
        <div class="btn_list">3</div>
        <div class="btn_list">4</div>
    </div>

    <script>
        let list = document.querySelectorAll('.cont_list')
        let btn = document.querySelectorAll('.btn_list')

        for (let i = 0; i < btn.length; i++) {
            btn[i].addEventListener('click', function () {
                for (let j = 0; j < list.length; j++) {
                    list[j].style.opacity = 0
                    list[j].style.zIndex = 0
                    btn[j].style.backgroundColor = '#ccc'
                }
                list[i].style.opacity = 1
                list[i].style.zIndex = 1
                btn[i].style.backgroundColor = 'red'
            })
        }
    </script>
</body>

</html>